package com.ruoyi.hatha.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hatha.domain.POfflineUser;
import com.ruoyi.hatha.service.IPOfflineUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 线下会员Controller
 * 
 * @author Dong
 * @date 2024-05-29
 */
@RestController
@RequestMapping("/hatha/offlineuser")
public class POfflineUserController extends BaseController
{
    @Autowired
    private IPOfflineUserService pOfflineUserService;

    /**
     * 查询线下会员列表
     */
    @PreAuthorize("@ss.hasPermi('hatha:offlineuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(POfflineUser pOfflineUser)
    {
        startPage();
        List<POfflineUser> list = pOfflineUserService.selectPOfflineUserList(pOfflineUser);
        return getDataTable(list);
    }

    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<POfflineUser> util = new ExcelUtil<POfflineUser>(POfflineUser.class);
        List<POfflineUser> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = pOfflineUserService.importUser(userList, false, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<POfflineUser> util = new ExcelUtil<POfflineUser>(POfflineUser.class);
        util.importTemplateExcel(response, "线下用户数据");
    }

    /**
     * 导出线下会员列表
     */
    @PreAuthorize("@ss.hasPermi('hatha:offlineuser:export')")
    @Log(title = "线下会员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, POfflineUser pOfflineUser)
    {
        List<POfflineUser> list = pOfflineUserService.selectPOfflineUserList(pOfflineUser);
        ExcelUtil<POfflineUser> util = new ExcelUtil<POfflineUser>(POfflineUser.class);
        util.exportExcel(response, list, "线下会员数据");
    }

    /**
     * 获取线下会员详细信息
     */
    @PreAuthorize("@ss.hasPermi('hatha:offlineuser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pOfflineUserService.selectPOfflineUserById(id));
    }

    /**
     * 新增线下会员
     */
    @PreAuthorize("@ss.hasPermi('hatha:offlineuser:add')")
    @Log(title = "线下会员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody POfflineUser pOfflineUser)
    {
        return toAjax(pOfflineUserService.insertPOfflineUser(pOfflineUser));
    }

    /**
     * 修改线下会员
     */
    @PreAuthorize("@ss.hasPermi('hatha:offlineuser:edit')")
    @Log(title = "线下会员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody POfflineUser pOfflineUser)
    {
        return toAjax(pOfflineUserService.updatePOfflineUser(pOfflineUser));
    }

    /**
     * 删除线下会员
     */
    @PreAuthorize("@ss.hasPermi('hatha:offlineuser:remove')")
    @Log(title = "线下会员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pOfflineUserService.deletePOfflineUserByIds(ids));
    }
}
